package com.lindenvalley.de.content;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;


@Root(strict=false)
public class Question {
	
	@Attribute(name="questions_id")
	private int id;
	
	private int sectionId;
	
	@Element(required=false)
	private String title;
	
	@Element(required=false)
	private String description;
	
	@Element(name="responsetype")
	private String responseType;
	
//	private Map<Integer, Answer> answers;
	@ElementList(inline=true, required=false)
	private List<Answer> answer;
	public static final String RESPONSE_TYPE_ORDINARY = "ordinary";
	public static final String RESPONSE_TYPE_MULTY = "multi";
	public static final String RESPONSE_TYPE_TEXT = "text";
	
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
//	/**
//	 * @return the sectionId
//	 */
//	public int getSectionId() {
//		return sectionId;
//	}
//	/**
//	 * @param sectionId the sectionId to set
//	 */
//	public void setSectionId(int sectionId) {
//		this.sectionId = sectionId;
//	}
	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}
	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	/**
	 * @return the responseType
	 */
	public String getResponseType() {
		return responseType;
	}
	/**
	 * @param responseType the responseType to set
	 */
	public void setResponseType(String responseType) {
		this.responseType = responseType;
	}
	/**
	 * @return the answers
	 */
//	public Map<Integer, Answer> getAnswers() {
//		return answers;
//	}
//	/**
//	 * @param answers the answers to set
//	 */
//	public void setAnswers(Map<Integer, Answer> answers) {
//		this.answers = answers;
//	}
//	
//	public void addAnswer(Answer answer){
//		if (answers == null){
//			answers = new HashMap<Integer, Answer>();
//		}
//		answers.put(answer.getId(), answer);
//	}
	/**
	 * @param answer the answer to set
	 */
	public void setAnswer(List<Answer> answer) {
		this.answer = answer;
	}
	/**
	 * @return the answer
	 */
	public List<Answer> getAnswer() {
		return answer;
	}
	
	public Answer getAnswerById(int id){
		Answer answerById = null;
		if (this.answer != null){
			for(Answer a : answer){
				if (a.getId() == id){
					answerById = a;
					break;
				}
					
			}
		}
		return answerById;
	}
	
	public List<Answer> getRightAnswers(){
		List<Answer> answers = null;
		if (answer != null){
			answers = new ArrayList<Answer>();
			for (Answer a: this.answer){
				if (a.isCorrect())
					answers.add(a);
			}
		}
		return answers;
	}
	
	public boolean isFillQuestion(){
		return description != null && description.length() > 0 && answer != null && answer.size() > 0;
	}
	
	public void setSectionId(int sectionId) {
		this.sectionId = sectionId;
	}
	
	public int getSectionId() {
		return sectionId;
	}
	
	
	

}
